import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import * as log4js from 'log4js'
import {getLogger} from '../logs/logger_manager'

let logger = getLogger();

export interface Response<T> {
    data: T;
}

@Injectable()
export class ResInterceptor<T> implements NestInterceptor<T, Response<T>> {
  intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>> {
    return next.handle().pipe(map(data => {
        // delete data.response
        // delete data.status
        logger.info(JSON.stringify(data));
        return data
    } ));
  }
}